package 反射;

import java.util.Random;
//import java.lang.reflect.*;
import org.junit.jupiter.api.Test;

public class test2 {
	@Test
	public void test2() throws Exception {
		int num = new Random().nextInt(3);// 0,1,2
		String classPath = "";
		switch (num) {
		case 0:
			classPath = "IO.File对象";
			break;
		case 1:
			classPath = "JDBC.jdbcTest1";
			break;
		case 2:
			classPath = "Proxy.CglibTest";
			break;
		}
		Object obj = getInstance(classPath);
		System.out.println(obj);
	}

	public Object getInstance(String classPath) throws Exception {
		Class class1 = Class.forName(classPath);
		return class1.newInstance();
	}
}